package com.enzo.prms.task.model;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.enzo.prms.common.base.to.BaseEntity;
import com.enzo.prms.common.util.DateUtil;

/**
 *
 * @author cyq
 *
 */
@Entity
@Table(name = "T_TASK")
public class Task extends BaseEntity {
    private static final long serialVersionUID = -7536910132988442376L;
    
    public Task(){
    	this.priority="4";
    }

    @Id
    @GeneratedValue
    @Column(name = "ID")
    private Integer id;

    //任务名
    @Column(name="TASK_NAME",length = 50,nullable = false)
    private String taskName;

    //优先级
    @Column(name="TASK_PRIORITY",length = 1,nullable = true,columnDefinition = "CHAR default 4")
    private String priority;

    //任务状态
    @Column(name="TASK_STATUS",length=1,nullable=true)
    private String status;

    //开始时间
    @Column(name = "START_TS", nullable = true,columnDefinition="TIMESTAMP")
	private Date startTs;
    
    @Transient
    private String startTimeStr;
    
    @Transient
    private boolean isOver;

    @ManyToOne(cascade={CascadeType.PERSIST},fetch=FetchType.LAZY)
    @JoinColumn(name="LIST_ID")
    private Tlist list;

    @Lob
    @Basic(fetch=FetchType.EAGER)
    @Column(name="NOTE",columnDefinition="TEXT",nullable=true)
    private String note;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getPriority() {
        return priority;
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }

    public Tlist getList() {
        return list;
    }

    public void setList(Tlist list) {
        this.list = list;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

	public Date getStartTs() {
		return startTs;
	}

	public void setStartTs(Date startTs) {
		this.startTs = startTs;
	}

	public String getStartTimeStr() {
		return DateUtil.formatDate(startTs, "");
	}

	public void setStartTimeStr(String startTimeStr) {
		this.startTimeStr = startTimeStr;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public boolean getIsOver() {
		Date now=new Date();
		if(startTs==null){
			return false;
		}else if(startTs.after(now)){
			return false;
		}
		return true;
	}

}
